<%@ page language="java" contentType="text/html;charset=UTF-8"
    pageEncoding="UTF-8"%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="Page-Enter" content="blendTrans(Duration=1.0)"/>
    <%@include file="/commons/commons.jsp" %>
    <title>小播放窗口</title>
	<%
		/**
			调用小窗口播放是需要父级页面添加调用iframe包含页面机顶盒响应事件的方法
			例：
			if($("mv_box")){
				if(window.mv_box){
					window.mv_box.checkMvKey(keycode);
				}else if($("mv_box").contentWindow){
					$("mv_box").contentWindow.checkMvKey(keycode);
				}
				//document.getElementById("mv_box").contentWindow.checkMvKey(keycode);
			}
			partner:
				用于调整平台，可以改变小窗口页面识别平台方式
		*/
		String f_cc_id=request.getParameter("contentid");//第一次传入id组或单个内容id
		String contentType=request.getParameter("contentType");
		int left = Integer.parseInt(request.getParameter("left"));
		int top = Integer.parseInt(request.getParameter("top"));
		int width = Integer.parseInt(request.getParameter("width"));
		int height = Integer.parseInt(request.getParameter("height"));
		String indexOf=request.getParameter("index");
		String mediaUrl = String.valueOf(request.getParameter("mediaUrl"));
		String focusFrame=request.getParameter("focusFrame");//是否显示机顶盒默认选框 0 显示 1不显示
		String mediastr = String.valueOf(request.getParameter("mediastr"));
		String partner=request.getParameter("partner");
		String mediaCode=request.getParameter("mediaCode");
		String index=request.getParameter("index");
		if(mediaCode==null){
			mediaCode="";
		}
		if(partner==null){
			partner=current_partner;
		}
		/* String cloudTwoPlaneUrl_=cloudTwoPlaneUrl;
		cloudTwoPlaneUrl_="http://122.224.212.84/web/"; //测试调整路径使用 */
		String transferUrl=cloudTwoPlaneUrl+"industry/individuation_play/xiangshan/video_transfer.jsp?contentType="+contentType+"&contentid="+f_cc_id+"&&top="+top+"&left="+left+"&width="+width+"&height="+height;
    %>
    
	<script type="text/javascript">
		(function(){
			try{
				if(<%=focusFrame%>==1){//去边框
					var STB = navigator.appName;
					if (STB == "ztebw" || STB == "Fhbw2.0") {//中兴 烽火
						iPanel.focusWidth = "0";
					} else if (STB == "JETU") {
						iPanel.focusWidth = "3";
					} else {
						iPanel.focusWidth = "-1";
					}
				}
			}catch(e){
				//console.info(e);
			}
		})();
	</script>
	<script language="JavaScript" type="text/JavaScript">
		var mp = new MediaPlayer();
		var mediaStr = "";
		var videoId = "";
		var videoCode = "";
		var auth_id = "";
		var partner="<%=partner%>";
		var index=parseInt("<%=index%>");
		var contentType="<%=contentType%>";
		var transferUrl="<%=transferUrl%>";
		var contentid="<%=f_cc_id%>";
		var speed = 1;
		window.onload = function(){
			if("ZTE"==partner){//平台为中兴时，url为添加
				mediaStr="<%=mediastr%>";
			}else{
				var mediaUrl="<%=mediaUrl%>";
				if(mediaUrl.indexOf("?")>=0){
					mediaUrl+="&accountinfo=:,<%=serverid%>,,,<%=mediaCode%>,,,,,,,,,,,1,END";
				}else{
					mediaUrl+="?accountinfo=:,<%=serverid%>,,,<%=mediaCode%>,,,,,,,,,,,1,END";
				}
				mediaStr = '[{mediaUrl:"'+mediaUrl+'",';
				mediaStr += 'mediaCode: "jsoncode1",';
				mediaStr += 'mediaType:2,';
				mediaStr += 'audioType:1,';
				mediaStr += 'videoType:1,';
				mediaStr += 'streamType:1,';
				mediaStr += 'drmType:1,';
				mediaStr += 'fingerPrint:0,';
				mediaStr += 'copyProtection:1,';
				mediaStr += 'allowTrickmode:1,';
				mediaStr += 'startTime:0,';
				mediaStr += 'endTime:20000,';
				mediaStr += 'entryID:"jsonentry1"}]';
			}
			stop();
			start();
		};

		//进入页面后直接播放
		function start(){
			initMediaPlay();		
			play();
		}

		//初始话mediaPlay对象
		function initMediaPlay(){
			var instanceId = mp.getNativePlayerInstanceID(); //读取本地的媒体播放实例的标识
			var playListFlag = 0; //Media Player 的播放模式。 0：单媒体的播放模式 (默认值)，1: 播放列表的播放模式
			var videoDisplayMode = 0; //MediaPlayer 对象对应的视频窗口的显示模式. 1: 全屏显示2: 按宽度显示，3: 按高度显示
			var height = <%=height%>;
			var width = <%=width%>;
			var left = <%=left%>;
			var top = <%=top%>;
			var muteFlag = 0; //0: 设置为有声 (默认值) 1: 设置为静音
			var subtitleFlag = 0; //字幕显示 
			var videoAlpha = 0; //视频的透明度
			var cycleFlag = 1;
			var randomFlag = 0;
			var autoDelFlag = 0;
			var useNativeUIFlag = 0;
	
			//初始话mediaplayer对象
			mp.initMediaPlayer(instanceId,playListFlag,videoDisplayMode,height,width,left,top,muteFlag,useNativeUIFlag,subtitleFlag,videoAlpha,cycleFlag,randomFlag,autoDelFlag);
			mp.setSingleMedia(mediaStr); //设置媒体播放器播放媒体内容
			mp.setAllowTrickmodeFlag(0); //设置是否允许trick操作。 0:允许 1：不允许
			mp.setNativeUIFlag(0); //播放器是否显示缺省的Native UI，  0:允许 1：不允许
			mp.setAudioTrackUIFlag(1);//设置音轨的本地UI显示标志 0:不允许 1：允许
			mp.setMuteUIFlag(1); //设置静音的本地UI显示标志 0:不允许 1：允许
			mp.setAudioVolumeUIFlag(1);//设置音量调节本地UI的显示标志 0:不允许 1：允许
			mp.refreshVideoDisplay();
		}
		
		function serverStop(){//播放结束方法
			if(contentType==6){
				var contentList=contentid.split(",");
				if((index+1)>=contentList.length){
					index=0
				}else{
					index=index+1;
				}
				transferUrl=transferUrl+"&index="+index;
				jumpPage();
			}else{
				stop();
				start();
			}
		}
		function jumpPage(){
			window.location.href=transferUrl;
		}
		function mute(){
			var plflag=mp.getMuteFlag();
		   	if(plflag == 0){
			 	mp.setMuteFlag(1);
		   	}else{
			 	mp.setMuteFlag(0);
		   	}
		}
		
		//播放
		function play(){
			mp.playFromStart();
		}
		
		//停止播放
		function stop(){
			mp.stop();
		}
		function pauseOrPlay(){
			if(playStat == "play"){
				speed = 1;
				pause();
			}else {
				speed = 1;
				playStat = "play";
				mplay()
			}
		}

		function pause(){ //停止
			speed = 1;
			playStat = "pause";
			mp.pause();
		}
		
		function mplay(){ //播放/暂停
			resume();
			mp.play();
		}
		
		function resume(){
			speed = 1;
			playStat = "play";
			mp.resume();
		}
		function volUp(){ //音量+
			var vol = mp.getVolume();
			vol = (vol <= 90 ? vol+10 : 100);
			mp.setVolume(vol);
		}
		
		function volDown(){ //音量-
			var vol = mp.getVolume();
			vol = (vol >= 10 ? vol-10 : 0);
			mp.setVolume(vol);
		}
		function fastForward() {//快进
			speed = speed * 2;
			if(speed > 32)
				speed = 2;
			mp.fastForward(speed);
			setTimeout(function(){resume()},5*1000);
		}
		   
		function fastRewind(){//快退
			speed = speed * 2;
			if(speed > 32)
			speed = 2;
			mp.fastRewind(-speed);
			setTimeout(function(){resume()},5*1000);
		}
		function swtichjy(){//静音
			   if(plflag == 0 ){ 
				 plflag=1;
			     mp.setMuteFlag(1);
			   }else{
			     plflag=0;
			     mp.setMuteFlag(0);
			   }
		}
		function returnParentMP(){//将播放器对象交给父级页面
			return mp;
		}
		function goUtility() {//机顶盒事件响应
			//eval("eventJson = " + Utility.getEvent());
			Josncheck("eventJson = " + Utility.getEvent());
			var typeStr = eventJson.type;
			switch(typeStr) {
				case "EVENT_MEDIA_BEGINING":
					return false;
				case "EVENT_MEDIA_ERROR":
					mediaError(eventJson);
					return false;
				case "EVENT_MEDIA_END":
					serverStop();
					return false;
				default :
					break;
			}
			return true;
		}
		function Josncheck(text) {
			var toJSON = window.eval;
			var returnValue;
			if(/((alert|on\w+|function\s+\w+)\s*\(\s*(['+\d\w](,?\s*['+\d\w]*)*)*\s*\))/.test(text)){
				console.log("xss攻击");
			}else if(/(<(script|iframe|embed|frame|frameset|object|img|applet|body|html|style|layer|link|ilayer|meta|bgsound))/.test(text)){
				console.log("xss攻击");
			}else {
				try{
					returnValue = toJSON("("+text+")");
				}catch (e) {
					console.log("json解析失败");
					try{
						returnValue = toJSON(text);
					}catch (e) {
						console.log("json解析失败2");
					}
				}
				return returnValue;

			}

		}

		function mediaError(eventJson) {//出现错误
			var code = eventJson.error_code;
			var type = eventJson.error_message;
		}

		function checkMvKey(keycode) {
			switch(keycode) {
				case 768: //播放事件
					goUtility();
					break;
				case 259://声音大
					volUp();
					break;
				case 260://声音小
					volDown();
					break;
				case 261://静音
					swtichjy();
					break;
			}
		}
		//iPanel.focusWidth = "-1";//焦点框宽度
	</script>
</head>
<body onUnload="stop();" style="background-color:transparent;">
</body>
</html>